﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Ninject;
using Ninject.Syntax;
using Ninject.Modules;

namespace MiniERP.Infrastructure.Injector
{
    public class NinjectDependencyResolver : IDependencyResolver
    {
        private IKernel kernel;

        public NinjectDependencyResolver()
        {
            kernel = new StandardKernel(OnNinjectModuleRegister());
            AddBindings();
        }

        protected virtual void AddBindings()
        {
            // put additional bindings here
        }

        protected virtual NinjectModule[] OnNinjectModuleRegister()
        {
            return null;
        }


        public object GetService(Type serviceType)
        {
            return kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return kernel.GetAll(serviceType);
        }

        public IBindingToSyntax<T> Bind<T>()
        {
            return kernel.Bind<T>();
        }

        public IKernel Kernel
        {
            get { return kernel; }
        }

    }
}
